package com.bigstar.lolen_e;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import android.content.Context;
import android.util.Log;

public class ChampionData {
	
	public static ArrayList<ChampionTemplate> champions = new ArrayList<ChampionTemplate>();
	
	public static void load(Context context){
		String data = null;
		if(champions.size() <= 0){
			try {
				data = Utils.getXMLFileFromAssets(context, "champions.xml");
				PullParserFromXML(data);
			} catch (IOException e) {
			}	
		}
	}
	
	public static void PullParserFromXML(String data) {
	      try {
	            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
	            factory.setNamespaceAware(true);
	            XmlPullParser xpp = factory.newPullParser();

	            xpp.setInput(new StringReader(data));
	            int eventType = xpp.getEventType();
	            ChampionTemplate champion = null;
	            while (eventType != XmlPullParser.END_DOCUMENT) {
	            	if(eventType == XmlPullParser.START_TAG){
	            		if(xpp.getName().equals("champion")){
	            			champion = new ChampionTemplate();
	            		}else if(xpp.getName().equals("name_en")){
	            			champion.name_en = xpp.nextText();
	            		}else if(xpp.getName().equals("nick_name")){
	            			champion.nick_name = xpp.nextText();
	            		}else if(xpp.getName().equals("rp_point")){
	            			champion.rp_point = Integer.parseInt(xpp.nextText());
	            		}else if(xpp.getName().equals("ip_point")){
	            			champion.ip_point = Integer.parseInt(xpp.nextText());
	            		}else if(xpp.getName().equals("damage")){
	            			champion.damage = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("damage_per_level")){
	            			champion.damage_per_level = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("health")){
	            			champion.health = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("health_per_level")){
	            			champion.health_per_level = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("mana")){
	            			champion.mana = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("mana_per_level")){
	            			champion.mana_per_level = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("range")){
	            			champion.range = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("move_speed")){
	            			champion.move_speed = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("attack_speed")){
	            			champion.attack_speed = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("attack_speed_per_level")){
	            			champion.attack_speed_per_level = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("armor")){
	            			champion.armor = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("armor_per_level")){
	            			champion.armor_per_level = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("mr")){
	            			champion.mr = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("mr_per_level")){
	            			champion.mr_per_level = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("health_regen")){
	            			champion.health_regen = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("health_regen_per_level")){
	            			champion.health_regen_per_level = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("mana_regen")){
	            			champion.mana_regen = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("mana_regen_per_level")){
	            			champion.mana_regen_per_level = Float.parseFloat(xpp.nextText());
	            		}else if(xpp.getName().equals("stat")){
	            			champion.stat = xpp.nextText();
	            		}else if(xpp.getName().equals("skill")){
	            			champion.skill_movie = xpp.nextText();
	            		}else if(xpp.getName().equals("tags")){
	            			champion.tags = xpp.nextText();
	            		}else if(xpp.getName().equals("champ_id")){
	            			champion.champ_id = Integer.parseInt(xpp.nextText());
	            		}
	                 }else if(eventType == XmlPullParser.END_TAG){
	                	 if(xpp.getName().equals("champion")){
	                		 champions.add(champion);
	                	 }
	                 }
	                eventType = xpp.next();
	            }
	      } catch (Exception e) {
	    	  Log.i("eror", e.toString());
	      }
	}
}